package com.ruoyi.merchant.controller;

import com.ruoyi.common.core.cg.pojo.IdCardOcr;
import com.ruoyi.merchant.service.FacePPOCRService;
import com.ruoyi.merchant.service.OcrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;


@RestController
@RequestMapping("/ocr")
public class OcrController {
    @Autowired
    private OcrService ocrService;
    @Autowired
    private FacePPOCRService facePPOCRService;
    @PostMapping("/idCardOcr")
    public IdCardOcr idCardOcr(@RequestPart("file") MultipartFile file ,Integer uid) {
        // 获取用户ID
        // 调用 OCR 服务
        IdCardOcr idCardOcr = ocrService.idCardOcr(file,uid);  // 传递用户ID
        return idCardOcr;
    }

    @PostMapping("/business-license")
    public String recognizeBusinessLicense(@RequestParam("file") MultipartFile file) {
        try {
            File imageFile = File.createTempFile("business-license", ".jpg");
            file.transferTo(imageFile);

            String result = facePPOCRService.recognizeBusinessLicense(imageFile);

            imageFile.delete();

            return result;
        } catch (IOException e) {
            e.printStackTrace();
            return "Error processing the file: " + e.getMessage();
        }
    }
}
